package com.zxl.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxl.common.mapper.SysApiMapper;
import com.zxl.common.mapper.SysRoleMapper;
import com.zxl.common.model.pojo.SysApi;
import com.zxl.common.model.pojo.SysRole;
import com.zxl.common.service.SysRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zxw
 * @since 2023-04-06
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Resource
    private SysRoleMapper sysRoleMapper;
    @Resource
    private SysApiMapper sysApiMapper;

    @Override
    public String checkUrl(String url, Integer roleId){
        //获得用户所有角色，的所有apiUrl
        Integer integer = sysRoleMapper.checkUrl(url, roleId);
        if(integer>0){
            return null;
        }else {
            SysApi entity = sysApiMapper.selectOne(new QueryWrapper<SysApi>()
                    .eq("url", url).select("name"));

            if(entity==null){
                return "接口不存在";
            }else {
                return entity.getName()+" 权限不足";
            }

        }

    }


}
